package com.sun.jdk8.mytest;

import org.junit.Test;

import java.util.*;

public class GetListRepeatItem {


    /**
     *  修改家庭单时遇到的问题
     * 1. list集合去重问题
     * 2. 获取list集合中重复的元素
     */
    @Test
    public void test04() {
        List<String> list = Arrays.asList("1614036784789333", "1614036784789333", "1614036784789222", "1614036784789111", "1", "1", "2", "3", "3");
        Set<String> set = new HashSet<>(list);
        System.out.println("把list集合存储到set集合去重" + set);

        // 得到list集合中重复的数据
        List<String> result = new ArrayList<>();
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                if (list.get(j).equals(list.get(i))) {
                    result.add(list.get(j));
                }
            }
        }
        result.forEach(System.out::println);

        Set<String> set1 = new HashSet<>();
        set1.add("aa");
        set1.add("bbb");
        set1.add("aa");
        System.out.println(set1);
    }
}
